<?php
/**
 * Created by PhpStorm.
 * User: nefa
 * Date: 2018/4/26
 * Time: 上午11:06
 */



require_once 'conf/global.inc';
require_once 'core/core.inc';
require_once 'core/function.inc';
require_once 'inc/PHPExcel-1.8/Classes/PHPExcel.php';


/**
 * 文件下载
 */
if (!empty($_REQUEST['downloadType'])){
    switch ($_REQUEST['downloadType']){
        case 1://提案信息下载
            if (!empty($_REQUEST['downloadID'])){
                $data = array();//街道工委  党派
                $tableheader = array('提案编号','提交人','街道工委','案由','提案状态','占位符','党派','主办单位','协办单位','重点提案','附议人','提案内容','提案建议','届次','提案类型','创建时间');
                $downloadID = $_REQUEST['downloadID'];

                $sql = "select
                a.id,
                b.realname,
                b.street,
                a.anyou,
                case a.state
                 when '1' then '待审查'
                 when '2' then '未立案'
                 when '3' then '待交办'
                 when '4' then '办理中'
                 when '5' then '待反馈'
                 when '6' then '办完结'
                end,
                b.username,
                b.party,
                s.unitname,
                t.unitname as xieban,
                case a.stress
                 when '1' then '是'
                 when '2' then '否'
                end,
                a.follower,
                a.content,
                a.advise,
                a.session,
                case a.type
                 when '1' then '经济类'
                 when '2' then '文教体卫'
                 when '3' then '政法统战政协'
                end,
                a.createtime
                 from proposal as a left join user as b on a.userid=b.id left join sponsor_unit as s on s.id=a.sponsor left join assist_unit as t on t.id=a.assist where a.id in(".$downloadID.")";


                $result = $GLOBALS['DB']->query($sql);
                while($res=$result->fetch()) {
                    $data[] = $res;
                }
                outputExcel($tableheader,$data,'提案信息');
            }
            break;
        case 2://用户信息下载

            /**
             * id 主键用户id
            username 用户名
            password 密码
            role 角色(1:超级管理员2:政协委员3:提案委员会
            4:交办单位 5:办理单位)
            photourl 头像地址
            realname 真实姓名
            sex 性别 (1:男2:女3:保密)
            session 届次
            age 年龄
            party 党派团体
            work 工作单位
            phone 电话号码
            street 所属街道工委
            createtime 创建时间
             */

            $data = array();
            $tableheader = array('唯一用户名','姓名','届次','性别','年龄','占位符','党派团体','工作单位','手机号码','街道工委','所属角色');
            $sql = "select a.username,a.realname,a.session,a.sex,a.age,a.id,a.party,a.work,a.phone,a.street,b.role from user as a left join usergroup as b on a.role = b.id";
            $result = $GLOBALS['DB']->query($sql);
            while($res=$result->fetch()) {
                $data[] = $res;
            }
            outputExcel($tableheader,$data,'用户信息');
            break;
    }
}



